package com.crm.business.crm.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.SqlParser;
import com.crm.common.crm.common.CrmModel;
import com.crm.common.crm.entity.PO.CrmContract;
import com.crm.common.crm.entity.PO.CrmField;
import com.crm.common.crm.entity.PO.CrmReceivablesPlan;
import com.crm.common.crm.entity.VO.CrmInfoNumVO;
import com.crm.common.ka.core.entity.BasePage;
import com.crm.common.ka.core.feign.crm.entity.CrmEventBO;
import com.crm.business.servlet.BaseMapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同表 Mapper 接口
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-05-27
 */
public interface CrmContractMapper extends BaseMapper<CrmContract> {

    /**
     * 通过id查询商机数据
     *
     * @param id id
     * @param userId 用户ID
     * @return data
     */
    public CrmModel queryById(@Param("id") Integer id, @Param("userId") Long userId);

    /**
     * 查询详情页数量
     * @param map map
     */
    public CrmInfoNumVO queryNum(Map<String, Object> map);

    void deleteMember(@Param("memberId") String memberId, @Param("id") Integer id);

    List<CrmReceivablesPlan> queryReceivablesPlansByContractId(Integer contractId);

    CrmReceivablesPlan queryReceivablesPlansByReceivablesId(Integer receivablesId);

    JSONObject querySubtotalByContractId(@Param("contractId") Integer contractId);

    BasePage<JSONObject> queryProductPageList(BasePage<Object> parse, @Param("contractId") Integer contractId);

    BasePage<JSONObject> queryReturnVisit(BasePage<Object> parse, @Param("contractId") Integer contractId, @Param("conditions") String conditions, @Param("nameList") List<CrmField> nameList);

    List<String> endContract(@Param("data") CrmEventBO crmEventBO);

    List<String> receiveContract(@Param("data") CrmEventBO crmEventBO);

    List<Integer> endContractList(@Param("userId") Long userId, @Param("time") Date time, @Param("expiringDay") Integer expiringDay);

    List<JSONObject> receiveContractList(@Param("userId") Long userId, @Param("time") Date time);

    String getNextNo(@Param("dateStr") String dateStr);

    /**
     * 大额数量
     * @return
     */
    Integer largeAmountNum(@Param("laiyuan") String laiyuan, @Param("qishu") String qishu);

    /**
     * 大额成交量，大额成交金额
     * @param laiyuan
     * @param qishu
     * @return
     */
    Map<String, Object> bigDealSum(@Param("laiyuan") String laiyuan, @Param("qishu") String qishu);

    /**
     * 根据客户Id查询合同信息
     * @param customerId 客户Id
     * @return 合同信息集合
     */
    String queryContractByCustomerId(@Param("customerId") Integer customerId);

    CrmContract queryContractById(@Param("contractId") Integer contractId);

    CrmContract queryContractByNum(@Param("num") String num);

    @SqlParser(filter = true)
    List<CrmContract> queryOrder(@Param("expireDate") Date expireDate);
}
